package com.test.pattern.interpret;

/**
 * @ClassName: Variable
 * @description: 终结符表达式角色,用于封装变量的类
 * @author: Mr du
 * @create: 2024-04-01 21:16
 */
public class Variable extends AbstractExpression{

    //声明存储变量名吃成员变量
    private String name;

    public Variable(String name) {
        this.name = name;
    }

    @Override
    public int interpret(Context context) {
        //直接存储变量的值
        return context.getValue(this);
    }

    @Override
    public String toString() {
        return name;
    }
}
